<template>
	<view>
		<!-- 所有内容的容器 -->
		<view class="u-m-t-20">
			<!-- 头像 -->
			<u-avatar :src="focusUserInfo.imagepath" size="large"></u-avatar>
			<u-cell-item style="float: right;width: 80%;" :arrow="arrow">
				<!-- 取消关注按钮 -->
				<u-button class="cancleBtn" size="mini" @click="cancleFocus()">取消关注</u-button>
				<!-- 消息提示 -->
				<u-toast ref="uToast" />
			</u-cell-item>
		</view>
		<!--关注个人基本信息-->
		<view class="u-m-t-20">
			<u-cell-item title="姓名" :value="focusUserInfo.username" :arrow="arrow"></u-cell-item>
			<u-cell-item v-if="focusUserInfo.sex == '1'" title="性别" value="男" :arrow="arrow"></u-cell-item>
			<u-cell-item v-else="focusUserInfo.sex == '2'" title="性别" value="女" :arrow="arrow"></u-cell-item>
		</view>
		<!-- 聊天按钮 -->
		<view class="u-m-t-30">
			<button type="info" size="medium" color="#dd6161">聊天</button>
		</view>
	</view>
	
</template>

<script>
	export default {
		data() {
			return {
				title: '关注个人中心',
				//当前用户信息
				userInfo: this.$store.state.user.userInfo,
				//关注个人用户信息
				focusUserInfo:{},
				arrow:false
				
			}
		},
		onLoad(option) {
			console.log('接收参数' + option.userId);
			//根据用户id查询用户信息
			uni.request({
			    url: this.$url + 'userinfo/getUserInfoByUserId', 
			    data: {
			        userId:option.userId
			    },
			    success: (res) => {
			        console.log("后台返回的数据：" + res.data.data);
					this.$data.focusUserInfo = res.data.data;
			    },
			});
			//将focus-page传过来的参数赋值给fUserInfo
			this.fUserInfo = option;
		},
		methods:{
			//取消关注
			cancleFocus(){
				uni.request({
				    url: this.$url + 'focus/delete',
				    data: {
						focusId:this.$data.focusUserInfo.userid,
				        userId:this.$data.userInfo.userid
				    },
				    success: (res) => {
				        console.log("后台返回的数据：" + res.data.data);
					   //如果取消成功
					   if(res.data.data > 0){
						//消息提示
						this.$refs.uToast.show({
							title: '取消关注成功！',
							type: 'success',	
						});
						setTimeout(function(){
							//返回上一页
							uni.navigateBack({
								 url: 'pages/person-second-page/focus-page/focus-page',
								 success: (res) =>{
									let page = getCurrentPages().pop();
									if (page) {
									   page.onLoad();//执行上个页面的方法
									};
								 }
							});
						},1200)
					   }else{
						//消息提示
						this.$refs.uToast.show({
							title: '取消关注失败！',
							type: 'error',	
						})	
					   }
				    }
				});
			}
		}
	}
</script>

<style>
.cancleBtn{
	background-color: red;
}
	
</style>

